//控制正价,折价销售调整额为上下20%,调整后任务与调整前相等
jQuery(document).ready(function() {

    //正价销售额
    var zjxseeFieldid = WfForm.convertFieldNameToId("zjxsee", "detail_1");
  //正价调整额
   var zjxsdzeFiled =WfForm.convertFieldNameToId("zjxsdze", "detail_1");
    //v8正价
    var v8zjxsField = WfForm.convertFieldNameToId("v8zjxs", "detail_1");

    //折价销售额
    var zjxseFieldid = WfForm.convertFieldNameToId("zjxse", "detail_1");
    //折价调整额
    var zjxsdzedField=WfForm.convertFieldNameToId("zjxsdzed", "detail_1");
    //v8折价
    var v8zjxssField = WfForm.convertFieldNameToId("v8zjxss", "detail_1");

    //正价销售额改变时
    WfForm.bindDetailFieldChangeEvent(zjxseeFieldid,
    function(id, index, value) {

        //v8正价值
        var v8zjxsVal = WfForm.getFieldValue(v8zjxsField + "_" + index);

        //预定任务浮动10%的区间值为
        var downVal = v8zjxsVal - v8zjxsVal * 0.2;


        var upVal = v8zjxsVal * 1 + v8zjxsVal * 0.2;

        //判断销售任务额是否在此区间内
        if (value <= upVal && value >= downVal) {

} else {
            alert("正价销售额需在v8正价销售额的±20%以内");
            WfForm.changeFieldValue(zjxsdzeFiled + "_" + index, {
                value: ""
            });

        }
    });

    //折价销售额改变时
    WfForm.bindDetailFieldChangeEvent(zjxseFieldid,
    function(id, index, value) {
        //v8折价值
        var v8zjxsVal = WfForm.getFieldValue(v8zjxssField + "_" + index);
        //预定任务浮动20%的区间值为
        var downVal = v8zjxsVal - v8zjxsVal * 0.2;
        var upVal = v8zjxsVal * 1 + v8zjxsVal * 0.2;
        //判断销售任务额是否在此区间内
        if (value <= upVal && value >= downVal) {

} else {
            alert("折价销售额需在v8折价销售额的±20%以内");
            WfForm.changeFieldValue(zjxsdzedField + "_" + index, {
                value: ""
            });

        }
    });



    checkCustomize = function() {

        //v8月任务
        var v8yrwField = WfForm.convertFieldNameToId("v8yrw", "detail_1");

        //月任务
        var yrwField = WfForm.convertFieldNameToId("yrw", "detail_1");

        //当前所有的明细下标
        var submitdtlid0 = WfForm.getDetailAllRowIndexStr("detail_1");


     //v8月任务总计
        var v8yrwSum = 0;
        //月任务总计
        var yrwSum = 0;

        if (submitdtlid0 != null) {
            var subArr = submitdtlid0.split(",");
            for (var index = 0; index < subArr.length; index++) {
                //v8月任务
                var v8yrwVal = WfForm.getFieldValue(v8yrwField + "_" + subArr[index]);

                //月任务
                var yrwVal = WfForm.getFieldValue(yrwField + "_" + subArr[index]);

                //v8月任务总计
                v8yrwSum = v8yrwSum + v8yrwVal * 1;
                //月任务总计
                yrwSum = yrwSum + yrwVal * 1;
            }
        }


        if ((v8yrwSum * 1) != (yrwSum * 1)) {
            alert("调整前任务要与调整后任务总和相等");
            return false;
        }
        return true;
    }
});